//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __ELASYSAPI_H__
#define __ELASYSAPI_H__

#include <elapi.h>

#ifdef __cplusplus

_ELASTOS_NAMESPACE_BEGIN

class CSystem
{
public:
    STATIC CARAPI RegisterRunningObject(
        /* [in] */ WString name,
        /* [in] */ PInterface pRunningObject)
    {
        return _CSystem_RegisterRunningObject(name, pRunningObject);
    }

    STATIC CARAPI FindRunningObject(
        /* [in] */ WString name,
        /* [out] */ PInterface *ppRunningObject)
    {
        return _CSystem_FindRunningObject(name, ppRunningObject);
    }

    STATIC CARAPI WaitForRunningObject(
        /* [in] */ WString name,
        /* [in] */ Millisecond32 timeout,
        /* [out] */ WaitResult *pResult)
    {
        return _CSystem_WaitForRunningObject(name, timeout, pResult);
    }

    STATIC CARAPI UnregisterRunningObject(
        /* [in] */ WString name)
    {
        return _CSystem_UnregisterRunningObject(name);
    }

    STATIC CARAPI GetMachineTime(
        /* [out] */ SystemTime *pMachineTime)
    {
        return _CSystem_GetMachineTime(pMachineTime);
    }

    STATIC CARAPI SetMachineTime(
        /* [in] */ SystemTime machineTime)
    {
        return _CSystem_SetMachineTime(machineTime);
    }

    STATIC CARAPI_(Millisecond32) GetElapsedTime()
    {
        return _CSystem_GetElapsedTime();
    }

    STATIC CARAPI_(Millisecond32) GetIdleTime()
    {
        return _CSystem_GetIdleTime();
    }

    STATIC CARAPI_(Int32) GetVersion()
    {
        return _CSystem_GetVersion();
    }

    STATIC CARAPI GetGlobalMemorySizes(
        /* [out] */ Int32 *pTotalPhysicalMemorySize,
        /* [out] */ Int32 *pAvailablePhysicalMemorySize)
    {
        return _CSystem_GetGlobalMemorySizes(
                    pTotalPhysicalMemorySize,
                    pAvailablePhysicalMemorySize);
    }

    STATIC CARAPI DebugPrint(
        /* [in] */ WString message)
    {
        return _CSystem_DebugPrint(message);
    }

    STATIC CARAPI GetAllProcesses(
        /* [out] */ IObjectEnumerator **ppProcesses)
    {
        return _CSystem_GetAllProcesses(ppProcesses);
    }

    STATIC CARAPI Reboot()
    {
        return _CSystem_Reboot();
    }

    STATIC CARAPI CreateSystemEventHandle(
        /* [in] */ SystemEvents interestedEvents,
        /* [out] */ IEvent **ppEvent)
    {
        return _CSystem_CreateSystemEventHandle(interestedEvents, ppEvent);
    }

    STATIC CARAPI WaitForAnySystemEvent(
        /* [in] */ SystemEvents interestedEvents,
        /* [out] */ SystemEvent *pSystemEvent)
    {
        return _CSystem_WaitForAnySystemEvent(interestedEvents, pSystemEvent);
    }

    STATIC CARAPI QueryPerformanceCounter(
        /* [out] */ Int64 *pPerformanceCount)
    {
        return _CSystem_QueryPerformanceCounter(pPerformanceCount);
    }

    STATIC CARAPI QueryPerformanceFrequency (
        /* [out] */ Int64 *pFrequency)
    {
        return _CSystem_QueryPerformanceFrequency(pFrequency);
    }
};

class CProcess
{
public:
    STATIC CARAPI New(
        /* [in] */ WString name,
        /* [in] */ WString args,
        /* [out] */ IProcess **ppProcess)
    {
        return _CProcess_New(name, args, ppProcess);
    }

    STATIC CARAPI New(
        /* [out] */ IProcess **ppProcess)
    {
        return _CProcess_NewUnstarted(ppProcess);
    }

    STATIC CARAPI_(IProcess *) GetCurrent()
    {
        return _CProcess_GetCurrent();
    }

    STATIC CARAPI_(void) Exit(
        /* [in] */ ExitCode exitCode)
    {
        _CProcess_Exit(exitCode);
    }

    STATIC CARAPI_(void) Terminate(
        /* [in] */ ExitCode exitCode)
    {
        _CProcess_Terminate(exitCode);
    }

    STATIC CARAPI AtExit(
        /* [in] */ PProcessExitRoutine pEntry,
        /* [in] */ PVoid pUserData)
    {
        return _CProcess_AtExit(pEntry, pUserData);
    }

    template <class T>
    STATIC CARAPI AtExit(
        /* [in] */ T * pThis,
        /* [in] */ void (ELAPICALLTYPE T::*pEntry)())
    {
        EventHandler delegate = EventHandler::Make(pThis, *(void **)&pEntry, CallbackType_CPP);
        return _CProcess_AtExit(
                (PProcessExitRoutine)delegate.GetFuncPtr(),
                delegate.GetThisPtr());
    }

    STATIC CARAPI FreeUnusedModule(WString wszDllName)
    {
        return _CProcess_FreeUnusedModule(wszDllName);
    }

    STATIC CARAPI_(void) FreeUnusedModules()
    {
        _CProcess_FreeUnusedModules(TRUE);
    }

    STATIC CARAPI FlushInstructionCache(
        /* [in] */ Address baseAddr,
        /* [in] */ MemorySize size)
    {
        return _CProcess_FlushInstructionCache(baseAddr, size);
    }
};

class CModule
{
public:
    STATIC CARAPI GetCurrent(
        /* [out] */ IModule **ppModule)
    {
        return _CModule_GetCurrent(ppModule);
    }

    STATIC CARAPI Load(
        /* [in] */ WString name,
        /* [in] */ ModuleLoadFlags flags,
        /* [out] */ IModule **ppModule)
    {
        return _CModule_Load(name, flags, ppModule);
    }
};

class CThread
{
public:
    STATIC CARAPI New(
        /* [in] */ PThreadMain pEntry,
        /* [in] */ PVoid pArg,
        /* [in] */ ThreadCreationFlags flags,
        /* [out] */ IThread **ppThread)
    {
        return _CThread_New(pEntry, pArg, flags, ppThread);
    }

    STATIC CARAPI AtQuit(
        /* [in] */ PThreadQuitRoutine pEntry,
        /* [in] */ PVoid pUserData)
    {
        return _CThread_AtQuit(pEntry, pUserData);
    }

    template <class T>
    STATIC CARAPI AtQuit(
        /* [in] */ T * pThis,
        /* [in] */ void (ELAPICALLTYPE T::*pEntry)())
    {
        EventHandler delegate = EventHandler::Make(pThis, *(void **)&pEntry, CallbackType_CPP);
        return _CThread_AtQuit(
                (PThreadQuitRoutine)delegate.GetFuncPtr(),
                delegate.GetThisPtr());
    }

    STATIC CARAPI_(IThread *) GetCurrent()
    {
        return _CThread_GetCurrent();
    }

    STATIC CARAPI_(void) Quit(
        /* [in] */ QuitCode quitCode)
    {
        _CThread_Quit(quitCode);
    }

    STATIC CARAPI Sleep(
        /* [in] */ Millisecond32 ms,
        /* [out] */ WaitResult *pResult)
    {
        return _CThread_Sleep(ms, pResult);
    }

    STATIC CARAPI Delay(
        /* [in] */ Microsecond32 us)
    {
        return _CThread_Delay(us);
    }

    STATIC CARAPI Yield()
    {
        return _CThread_Yield();
    }

    STATIC CARAPI AcquireLocalSlot(
        /* [in] */ ThreadLocalSlotType slotType,
        /* [out] */ Int32 *pSlotIndex)
    {
        return _CThread_AcquireLocalSlot(slotType, pSlotIndex);
    }

    STATIC CARAPI RelinquishLocalSlot(
        /* [in] */ Int32 slotIndex)
    {
        return _CThread_RelinquishLocalSlot(slotIndex);
    }

    STATIC CARAPI SetLocalValue(
        /* [in] */ Int32 slotIndex,
        /* [in] */ TLValue value)
    {
        return _CThread_SetLocalValue(slotIndex, value);
    }

    STATIC CARAPI SetLocalMemory(
        /* [in] */ Int32 slotIndex,
        /* [in] */ PVoid pMemory)
    {
        return _CThread_SetLocalMemory(slotIndex, pMemory);
    }

    STATIC CARAPI SetLocalObject(
        /* [in] */ Int32 slotIndex,
        /* [in] */ PInterface pObject)
    {
        return _CThread_SetLocalObject(slotIndex, pObject);
    }

    STATIC CARAPI GetLocalValue(
        /* [in] */ Int32 slotIndex,
        /* [out] */ TLValue *pValue)
    {
        return _CThread_GetLocalValue(slotIndex, pValue);
    }

    STATIC CARAPI GetLocalMemory(
        /* [in] */ Int32 slotIndex,
        /* [out] */ PVoid *ppMemory)
    {
        return _CThread_GetLocalMemory(slotIndex, ppMemory);
    }

    STATIC CARAPI GetLocalObject(
        /* [in] */ Int32 slotIndex,
        /* [out] */ PInterface *ppObj)
    {
        return _CThread_GetLocalObject(slotIndex, ppObj);
    }
};

class CMemoryHeap
{
public:
    STATIC CARAPI_(PVoid) Alloc(
        /* [in] */ MemorySize size,
        /* [in] */ Boolean zeroMemory)
    {
        return _CMemoryHeap_Alloc(size, zeroMemory);
    }

    STATIC CARAPI_(PVoid) Realloc(
        /* [in] */ PVoid pMemory,
        /* [in] */ MemorySize size)
    {
        return _CMemoryHeap_Realloc(pMemory, size);
    }

    STATIC CARAPI_(void) Free(
        /* [in] */ PVoid pMemory)
    {
        _CMemoryHeap_Free(pMemory);
    }

    STATIC CARAPI_(Boolean) Trim(
        /* [in] */ MemorySize pad)
    {
        return _CMemoryHeap_Trim(pad);
    }

    STATIC CARAPI GetStatistics(
        /* [out] */ MemorySize *pInUseBytes,
        /* [out] */ MemorySize *pSystemBytes,
        /* [out] */ MemorySize *pMaxSystemBytes)
    {
        return _CMemoryHeap_GetStatistics(
                pInUseBytes, pSystemBytes, pMaxSystemBytes);
    }
};

class CVirtualMemory
{
public:
    STATIC CARAPI Alloc(
        /* [in] */ Address baseAddr,
        /* [in] */ MemorySize size,
        /* [in] */ MemoryMapFlags flags,
        /* [in] */ MemoryProtection protection,
        /* [out] */ Address *pBaseAddr)
    {
        return _CVirtualMemory_Alloc(
                baseAddr, size, flags, protection, pBaseAddr);
    }

    STATIC CARAPI Query(
        /* [in] */ Address address,
        /* [out] */ Address *pBaseAddr,
        /* [out] */ MemorySize *pSize)
    {
        return _CVirtualMemory_Query(address, pBaseAddr, pSize);
    }

    STATIC CARAPI QueryPhysicalBlock(
        /* [in] */ Address address,
        /* [out] */ Address *pAddress,
        /* [out] */ MemorySize *pSize)
    {
        return _CVirtualMemory_QueryPhysicalBlock(address, pAddress, pSize);
    }

    STATIC CARAPI SetProtection(
        /* [in] */ Address baseAddr,
        /* [in] */ MemorySize size,
        /* [in] */ MemoryProtection protection)
    {
        return _CVirtualMemory_SetProtection(baseAddr, size, protection);
    }

    STATIC CARAPI CheckProtection(
        /* [in] */ Address address,
        /* [in] */ MemoryProtection protection,
        /* [out] */ Boolean *pIsValid)
    {
        return _CVirtualMemory_CheckProtection(address, protection, pIsValid);
    }

    STATIC CARAPI Commit(
        /* [in] */ Address address)
    {
        return _CVirtualMemory_Commit(address);
    }

    STATIC CARAPI Free(
        /* [in] */ Address baseAddr,
        /* [in] */ MemorySize size)
    {
        return _CVirtualMemory_Free(baseAddr, size);
    }

    STATIC CARAPI IoRemap(
        /* [in] */ Address virtualAddr,
        /* [in] */ MemorySize size,
        /* [in] */ Address physicalAddr,
        /* [in] */ MemoryMapFlags flags,
        /* [in] */ Int32 protection,
        /* [out] */ Address *pVirtualAddr)
    {
        return _CVirtualMemory_IoRemap(
                    virtualAddr,
                    size,
                    physicalAddr,
                    flags,
                    protection,
                    pVirtualAddr);
    }
};

class CMutex
{
public:
    STATIC CARAPI New(
        /* [out] */ IMutex **ppMutex)
    {
        return _CMutex_New(ppMutex);
    }

    STATIC CARAPI New(
        /* [in] */ WString name,
        /* [out] */ IMutex **ppMutex,
        /* [out] */ Boolean *pAlreadyExists)
    {
        return _CMutex_NewWithName(name, ppMutex, pAlreadyExists);
    }
};

class CCondition
{
public:
    STATIC CARAPI New(
        /* [out] */ ICondition **ppCondition)
    {
        return _CCondition_New(ppCondition);
    }

    STATIC CARAPI New(
        /* [in] */ WString name,
        /* [out] */ ICondition **ppCondition,
        /* [out] */ Boolean *pAlreadyExists)
    {
        return _CCondition_NewWithName(name, ppCondition, pAlreadyExists);
    }
};

class CEvent
{
public:
    STATIC CARAPI New(
        /* [in] */ Boolean manualReset,
        /* [in] */ EventState initialState,
        /* [out] */ IEvent **ppEvent)
    {
        return _CEvent_New(manualReset, initialState, ppEvent);
    }

    STATIC CARAPI New(
        /* [in] */ WString name,
        /* [in] */ Boolean manualReset,
        /* [in] */ EventState initialState,
        /* [out] */ IEvent **ppEvent,
        /* [out] */ Boolean *pAlreadyExists)
    {
        return _CEvent_NewWithName(
                name, manualReset, initialState, ppEvent, pAlreadyExists);
    }

    STATIC CARAPI WaitForAnyEvents(
        /* [in] */ const BufferOf<IEvent *> & events,
        /* [out] */ WaitResult *pResult,
        /* [out] */ Int32 *pIndex,
        /* [out] */ EventState *pState)
    {
        return _CEvent_WaitForAnyEvents(&events, pResult, pIndex, pState);
    }

    STATIC CARAPI TryWaitForAnyEvents(
        /* [in] */ const BufferOf<IEvent *> & events,
        /* [in] */ Millisecond32 timeout,
        /* [out] */ WaitResult *pResult,
        /* [out] */ Int32 *pIndex,
        /* [out] */ EventState *pState)
    {
        return _CEvent_TryWaitForAnyEvents(
                &events, timeout, pResult, pIndex, pState);
    }
};

class CReaderWriterLock
{
public:
    STATIC CARAPI New(
        /* [out] */ IReaderWriterLock **ppRWLock)
    {
        return _CReaderWriterLock_New(ppRWLock);
    }

    STATIC CARAPI New(
        /* [in] */ WString name,
        /* [out] */ IReaderWriterLock **ppRWLock,
        /* [out] */ Boolean *pAlreadyExists)
    {
        return _CReaderWriterLock_NewWithName(name, ppRWLock, pAlreadyExists);
    }
};

class CSharedMemory
{
public:
    STATIC CARAPI New(
        /* [in] */ WString name,
        /* [in] */ MemorySize size,
        /* [in] */ Boolean reserved,
        /* [out] */ ISharedMemory **ppSharedMemory,
        /* [out] */ Boolean *pAlreadyExists)
    {
        return _CSharedMemory_New(
                name, size, reserved, ppSharedMemory, pAlreadyExists);
    }
};

class CErrorReport
{
public:
    STATIC CARAPI SetWString(
        /* [in] */ WString string)
    {
        return _CErrorReport_SetWString(string);
    }

    STATIC CARAPI SetAString(
        /* [in] */ AString string)
    {
        return _CErrorReport_SetAString(string);
    }

    STATIC CARAPI SetUrl(
        /* [in] */ AString url)
    {
        return _CErrorReport_SetUrl(url);
    }

    STATIC CARAPI_(WString) GetWString()
    {
        return _CErrorReport_GetWString();
    }

    STATIC CARAPI_(AString) GetAString()
    {
        return _CErrorReport_GetAString();
    }

    STATIC CARAPI_(AString) GetUrl()
    {
        return _CErrorReport_GetUrl();
    }
};

class CReflector
{
public:
    STATIC CARAPI AcquireModuleInfo(
        /* [in] */ WString name,
        /* [out] */ IModuleInfo **ppModuleInfo)
    {
        return _CReflector_AcquireModuleInfo(name, ppModuleInfo);
    }

    STATIC CARAPI AcquireIntrinsicTypeInfo(
        /* [in] */ CarDataType intrinsicType,
        /* [out] */ IDataTypeInfo **ppIntrinsicTypeInfo)
    {
        return _CReflector_AcquireIntrinsicTypeInfo(intrinsicType,
            ppIntrinsicTypeInfo);
    }

    STATIC CARAPI AcquireEnumInfo(
        /* [in] */ AString name,
        /* [in] */ const BufferOf<AString>& itemNames,
        /* [in] */ const BufferOf<Int32>& itemValues,
        /* [out] */ IEnumInfo **ppEnumInfo)
    {
        return _CReflector_AcquireEnumInfo(name, &itemNames, &itemValues,
            ppEnumInfo);
    }

    STATIC CARAPI AcquireCppVectorInfo(
        /* [in] */ IDataTypeInfo *pElementTypeInfo,
        /* [in] */ Int32 length,
        /* [out] */ ICppVectorInfo **ppCppVectorInfo)
    {
        return _CReflector_AcquireCppVectorInfo(pElementTypeInfo, length,
            ppCppVectorInfo);
    }

    STATIC CARAPI AcquireStructInfo(
        /* [in] */ AString name,
        /* [in] */ const BufferOf<AString>& fieldNames,
        /* [in] */ const BufferOf<IDataTypeInfo *>& fieldTypeInfos,
        /* [out] */ IStructInfo **ppStructInfo)
    {
        return _CReflector_AcquireStructInfo(name, &fieldNames,
            &fieldTypeInfos, ppStructInfo);
    }

    STATIC CARAPI AcquireCarArrayInfo(
        /* [in] */ CarDataType quintetType,
        /* [in] */ IDataTypeInfo *pElementTypeInfo,
        /* [out] */ ICarArrayInfo **ppCarArrayInfo)
    {
        return _CReflector_AcquireCarArrayInfo(quintetType, pElementTypeInfo,
            ppCarArrayInfo);
    }
};

class CObject
{
public:
    STATIC CARAPI_(Boolean) Compare(
        /* [in] */ PInterface pObjectA,
        /* [in] */ PInterface pObjectB)
    {
        return _CObject_Compare(pObjectA, pObjectB);
    }

    STATIC CARAPI ReleaseAtProcessExit(
        /* [in] */ PInterface pObject)
    {
        return _CObject_ReleaseAtProcessExit(pObject);
    }

    STATIC CARAPI ReleaseAtThreadQuit(
        /* [in] */ PInterface pObject)
    {
        return _CObject_ReleaseAtThreadQuit(pObject);
    }

    STATIC CARAPI ReleaseAtAppletFinish(
        /* [in] */ PInterface pObject)
    {
        return _CObject_ReleaseAtAppletFinish(pObject);
    }

    STATIC CARAPI EnterContext(PInterface pObject, PContext pContext)
    {
        return _CObject_EnterContext(pObject, pContext);
    }

    STATIC CARAPI LeaveContext(PInterface pObject, PContext pContext)
    {
        return _CObject_LeaveContext(pObject, pContext);
    }

    STATIC CARAPI EnterContext(PInterface pObject, PInterface pCtxObj)
    {
        PContext pContext = IContext::Probe(pCtxObj);
        if (!pContext) return E_NO_INTERFACE;
        return _CObject_EnterContext(pObject, pContext);
    }

    STATIC CARAPI LeaveContext(PInterface pObject, PInterface pCtxObj)
    {
        PContext pContext = IContext::Probe(pCtxObj);
        if (!pContext) return E_NO_INTERFACE;
        return _CObject_LeaveContext(pObject, pContext);
    }

    STATIC CARAPI CreateInstance(
        RClassID rclsid,
        PContext pContext,
        REIID riid,
        PInterface *ppObj)
    {
        return _CObject_CreateInstance(rclsid, pContext, riid, ppObj);
    }

    STATIC CARAPI CreateInstanceEx(
        RClassID rclsid,
        PContext pContext,
        UInt32 cmq,
        PMULTIQI pResults)
    {
        return _CObject_CreateInstanceEx(rclsid, pContext, cmq, pResults);
    }

    STATIC CARAPI AcquireClassFactory(
        RClassID rclsid,
        PContext pContext,
        PInterface *ppObject)
    {
        return _CObject_AcquireClassFactory(rclsid, pContext, ppObject);
    }

    STATIC CARAPI ReflectModuleInfo(
        PInterface pObj,
        IModuleInfo **piModuleInfo)
    {
        return _CObject_ReflectModuleInfo(pObj, piModuleInfo);
    }

    STATIC CARAPI ReflectClassInfo(
        PInterface pObj,
        IClassInfo **piClassInfo)
    {
        return _CObject_ReflectClassInfo(pObj, piClassInfo);
    }

    STATIC CARAPI ReflectInterfaceInfo(
        PInterface pObj,
        IInterfaceInfo **piInterfaceInfo)
    {
        return _CObject_ReflectInterfaceInfo(pObj, piInterfaceInfo);
    }
};

class CApplet
{
public:
    STATIC CARAPI Finish(AppletFinish Flag)
    {
        IApplet* pApplet = NULL;
        ECode ec = _CApplet_GetCurrent((PInterface*)&pApplet);
        if (FAILED(ec) && E_NOT_IN_ANY_APPLET != ec) return NULL;

        if (pApplet) {
            ec = pApplet->Finish(Flag);
            pApplet->Release();
        }
        else {
            ec = _Impl_CallbackSink_RequestToFinish(NULL, Flag);
        }
        return ec;
    }

    STATIC CARAPI_(IApplet *) GetCurrent()
    {
        IApplet* pApplet = NULL;
        ECode ec = _CApplet_GetCurrent((PInterface*)&pApplet);
        if (FAILED(ec)) return NULL;

        pApplet->Release();

        return pApplet;
    }

    STATIC CARAPI GetAllThreads(IObjectEnumerator** ppThreads)
    {
        return _CApplet_GetAllThreads(ppThreads);
    }

    STATIC CARAPI AtFinish(
        /* [in] */ PThreadQuitRoutine pEntry,
        /* [in] */ PVoid pUserData)
    {
        return _CApplet_AtFinish(pEntry, pUserData);
    }

    template <class T>
    STATIC CARAPI AtFinish(
        /* [in] */ T * pThis,
        /* [in] */ void (ELAPICALLTYPE T::*pEntry)())
    {
        EventHandler delegate = EventHandler::Make(pThis, *(void **)&pEntry, CallbackType_CPP);
        return _CApplet_AtFinish(
                (PThreadQuitRoutine)delegate.GetFuncPtr(),
                delegate.GetThisPtr());
    }

    STATIC CARAPI_(AppletStatus) GetStatus()
    {
        PInterface pCallbackContext = NULL;
        _Impl_CallbackSink_GetCallbackContext(&pCallbackContext);
        AppletStatus cbStat =
                            _Impl_CallbackSink_GetStatus(pCallbackContext);
        pCallbackContext->Release();
        return cbStat;
    }

    STATIC CARAPI SetCurrentDirectory(
        /* [in] */ const WString & path)
    {
        IApplet* pApplet = NULL;
        ECode ec = _CApplet_GetCurrent((PInterface*)&pApplet);
        if (FAILED(ec)) return ec;

        ec = pApplet->SetCurrentDirectory(path);

        pApplet->Release();
        return ec;
    }

    STATIC CARAPI GetCurrentDirectory(
        /* [out] */ WStringBuf* pPath)
    {
        IApplet* pApplet = NULL;
        ECode ec = _CApplet_GetCurrent((PInterface*)&pApplet);
        if (FAILED(ec)) return ec;

        ec = pApplet->GetCurrentDirectory(pPath);

        pApplet->Release();
        return ec;
    }

    STATIC CARAPI GetCurrentDirectoryInStorage(
        /* [in] */  WString storage,
        /* [out] */ WStringBuf* path)
    {
        IApplet* pApplet = NULL;
        ECode ec = _CApplet_GetCurrent((PInterface*)&pApplet);
        if (FAILED(ec)) return ec;

        ec = pApplet->GetCurrentDirectoryInStorage(storage, path);

        pApplet->Release();
        return ec;
    }

    STATIC CARAPI SetEnvironmentVariable(
        /* [in] */  WString name,
        /* [in] */  WString value)
    {
        IApplet* pApplet = NULL;
        ECode ec = _CApplet_GetCurrent((PInterface*)&pApplet);
        if (FAILED(ec)) return ec;

        ec = pApplet->SetEnvironmentVariable(name, value);

        pApplet->Release();
        return ec;
    }

    STATIC CARAPI GetEnvironmentVariable(
        /* [in] */  WString name,
        /* [out] */ WStringBuf* value)
    {
        IApplet* pApplet = NULL;
        ECode ec = _CApplet_GetCurrent((PInterface*)&pApplet);
        if (FAILED(ec)) return ec;

        ec = pApplet->GetEnvironmentVariable(name, value);

        pApplet->Release();
        return ec;
    }
};

class CProfile
{
public:
    STATIC CARAPI GetAString(
        /* [in] */ AString appName,
        /* [in] */ AString keyName,
        /* [out] */ AStringBuf *pReturnedString)
    {
        return _CProfile_GetAString(
                appName, keyName, pReturnedString);
    }

    STATIC CARAPI GetWString(
        /* [in] */ WString appName,
        /* [in] */ WString keyName,
        /* [out] */ WStringBuf *pReturnedString)
    {
        return _CProfile_GetWString(
                appName, keyName, pReturnedString);
    }

    STATIC CARAPI GetInt32(
        /* [in] */ AString appName,
        /* [in] */ AString keyName,
        /* [out] */ Int32 *pValue)
    {
        return _CProfile_GetInt32(appName, keyName, pValue);
    }
};

class CPrivateProfile
{
public:
    STATIC CARAPI GetAString(
        /* [in] */ AString fileName,
        /* [in] */ AString appName,
        /* [in] */ AString keyName,
        /* [out] */ AStringBuf *pReturnedString)
    {
        return _CPrivateProfile_GetAString(fileName,
                appName, keyName, pReturnedString);
    }

    STATIC CARAPI GetWString(
        /* [in] */ WString fileName,
        /* [in] */ WString appName,
        /* [in] */ WString keyName,
        /* [out] */ WStringBuf *pReturnedString)
    {
        return _CPrivateProfile_GetWString(fileName,
                appName, keyName, pReturnedString);
    }

    STATIC CARAPI GetInt32(
        /* [in] */ AString fileName,
        /* [in] */ AString appName,
        /* [in] */ AString keyName,
        /* [out] */ Int32 *pValue)
    {
        return _CPrivateProfile_GetInt32(fileName, appName, keyName, pValue);
    }

    STATIC CARAPI SetAString(
        /* [in] */ AString fileName,
        /* [in] */ AString appName,
        /* [in] */ AString keyName,
        /* [in] */ AString value)
    {
        return _CPrivateProfile_SetAString(fileName,
                appName, keyName, value);
    }

    STATIC CARAPI SetWString(
        /* [in] */ WString fileName,
        /* [in] */ WString appName,
        /* [in] */ WString keyName,
        /* [in] */ WString value)
    {
        return _CPrivateProfile_SetWString(fileName,
                appName, keyName, value);
    }
};

class CActiveTimer
{
public:
    STATIC CARAPI New(
        /* [in] */ Millisecond32 interval,
        /* [in] */ ECode (ELAPICALLTYPE *pEntry)(PVoid, IActiveTimer *),
        /* [in] */ PVoid pUserData,
        /* [out] */ IActiveTimer ** ppActiveTimer)
    {
        return _CActiveTimer_New(interval, pEntry, pUserData, ppActiveTimer);
    }

    template <class T>
    STATIC CARAPI New(
        /* [in] */ Millisecond32 interval,
        /* [in] */ T * pThis,
        /* [in] */ ECode (ELAPICALLTYPE T::*pEntry)(IActiveTimer *),
        /* [out] */ IActiveTimer ** ppActiveTimer)
    {
        EventHandler d = EventHandler::Make((void *)pThis, *(void **)&pEntry, CallbackType_CPP);
        return _CActiveTimer_New(
            interval,
            (ECode (ELAPICALLTYPE *)(PVoid, IActiveTimer *))d.GetFuncPtr(),
            d.GetThisPtr(),
            ppActiveTimer);
    }
};

_ELASTOS_NAMESPACE_END

#endif // __cplusplus

#endif // __ELASYSAPI_H__
